let tableIns;
let tree;
let startDateIns;
let endDateIns;
layui.use(['element', 'form', 'table', 'layer', 'laydate', 'tree', 'util','upload'], function () {
    let table = layui.table;
    let form = layui.form;//select、单选、复选等依赖form
    let element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
    let laydate = layui.laydate;
    let upload = layui.upload;
    tree = layui.tree;
    var $=layui.jquery;
    let height = document.documentElement.clientHeight - 60;
    

    tableIns = table.render({
        elem: '#quarterListTable'
        , url: '/platform/grant/queryByHistory'
        , method: 'GET'
        //请求前参数处理
        , where: {
        	paytaxName: ""
        	,starSalesInto : ""
        	,endSalesInto : ""
        	,startaxMoney : ""
        	,endtaxMoney : ""
        	,starStarTime : ""
        	,endStarTime : ""
        	,starEndTime : ""
        	,endEndTime : ""
        	,taxNumber : ""
        }
    	, request: {
            pageName: 'page' //页码的参数名称，默认：page
                , limitName: 'rows' //每页数据量的参数名，默认：limit
            }
        , response: {
            statusName: 'flag' //规定数据状态的字段名称，默认：code
                , statusCode: true //规定成功的状态码，默认：0
                , msgName: 'msg' //规定状态信息的字段名称，默认：msg
                , countName: 'records' //规定数据总数的字段名称，默认：count
                , dataName: 'rows' //规定数据列表的字段名称，默认：data
            }
            //响应后数据处理
            , parseData: function (res) { //res 即为原始返回的数据
                var data = res.data;
                return {
                    "flag": res.flag, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "records": data.records, //解析数据长度
                    "rows": data.rows //解析数据列表
                };
          }
        , toolbar: '#quarterListTableToolbar'
        ,title: '用户个税数据表'
        ,defaultToolbar: ['filter', 'exports', 'print']
        , cols: [[
              {type:'checkbox'}
            , {field: 'payTaxName',title: '纳税人名称'}
            , {field: 'taxNumber',title: '税号'}
            , {field: 'taxType',title: '税种'}
            , {field: 'salesInto',title: '收入'}
            , {field: 'taxMoney',title: '税额'}
            , {field: 'starstarTime',title: '税款所属开始时间', templet: function(d){return d.starstarTime.substring(0,10);}}
            , {field: 'starendTime',title: '税款所属结束时间', templet: function(d){return d.starendTime.substring(0,10);}}
        ]]
        , page: true
        , height: height
        , cellMinWidth: 80
    });
    

    
    
  //头工具栏事件
    table.on('toolbar(display)', function (obj) {
    	switch (obj.event) {
    	case 'importExcel':
    			layer.open({
                    type: 2,
                    title: '导入Excel',
                    closeBtn: 1, //显示关闭按钮
                    anim: 2,
                    area: ['400px', '350px'],
                    shadeClose: true, //开启遮罩关闭
                    content: '/platform/grant/inthistory'
                });
    							
    		break;
    	}
    	
    

    	});
    

    $("#queryBtn,.click_btn").click(function(){
        var paytaxName = $("#paytaxName").val();
        var starSalesInto = $("#starSalesInto").val();
        var endSalesInto = $("#endSalesInto").val();
        var startaxMoney = $("#startaxMoney").val();
        var endtaxMoney = $("#endtaxMoney").val();
        var starStarTime = $("#starStarTime").val();
        var endStarTime = $("#endStarTime").val();
        var starEndTime = $("#starEndTime").val();
        var endEndTime = $("#endEndTime").val();
        var taxNumber = $("#taxNumber").val();
        let query = {
            done: function (res, curr, count) {
                //完成后重置where，解决下一次请求携带旧数据
                this.where = {};
            }
        };
        //设定异步数据接口的额外参数
        query.where = {
        		paytaxName: paytaxName
        		,starSalesInto : starSalesInto
                ,endSalesInto : endSalesInto
                ,startaxMoney : startaxMoney
                ,endtaxMoney : endtaxMoney
                ,starStarTime : starStarTime
                ,endStarTime : endStarTime
                ,starEndTime : starEndTime
                ,endEndTime : endEndTime
                ,taxNumber : taxNumber
        };
        //console.info(query.where);
        tableIns.reload(query);

    })
    
     $("#submitButton,.click_btn").click(function(){
    	 var data = new FormData();
    	 data.append('excelUploadFile', $('#excelUploadFile')[0].files[0]);
    	 layer.msg("请稍等！");
    	    $("#submitBtn").addClass("layui-btn-disabled");
    	    $("#submitBtn").unbind("click");
    	    $.ajax({
    	        type: "post",
    	        url: '/platform/grant/importData',
    	        cache:false,
    	        processData: false,
    	        contentType: false,
    	        data: data,
    	        dataType: "json",
    	        success: function (data) {
    	        	layer.alert(data);
    	           // vms.cancel();
    	           // parent.layui.table.reload('LAY-app-content-list');
    	        },
    	        error: function (data) {
    	        	layer.alert(data.responseText, {icon: 1,closeBtn: 0 },
                			function(){
    	        		 parent.layer.closeAll();
    	        		 parent.layui.table.reload('quarterListTable');
                	});
    	        }
    	    });
     });
    
    $("#closeButton,.click_btn").click(function(){
    	parent.layer.closeAll();
    });
    
    $("#exportButton,.click_btn").click(function(){
    	location.href= '/platform/grant/exportem';
    });
    
  //日期选择器
    startDateIns = laydate.render({
        elem: '#starStarTime',
        format: "yyyy-MM-dd",
        trigger: 'click'
    });
  //日期选择器
    startDateIns = laydate.render({
        elem: '#endStarTime',
        format: "yyyy-MM-dd",
        trigger: 'click'
    });
  //日期选择器
    startDateIns = laydate.render({
        elem: '#starEndTime',
        format: "yyyy-MM-dd",
        trigger: 'click'
    });
  //日期选择器
    startDateIns = laydate.render({
        elem: '#endEndTime',
        format: "yyyy-MM-dd",
        trigger: 'click'
    });
    


});








